package com.account.controller;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入笔记文件目录路径:");
        String srcNotePath, outNotepath;
        while (true) {
            srcNotePath = sc.nextLine();
            File temp = new File(srcNotePath);
            if (!temp.exists())
                System.out.println("该目录不存在");
            else
                break;
        }
        System.out.println("请输入笔记文件输出目录: ");
        while (true) {
            outNotepath = sc.nextLine();
            File temp = new File(outNotepath);
            if (!temp.exists()) {
                temp.mkdir();
                System.out.println("该目录不存在");
            } else
                break;
        }
        FileProcess fileProcess = new FileProcess(srcNotePath, outNotepath);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
        File file = new File(outNotepath + File.separator + simpleDateFormat.format(new Date()) + ".log");
        if (file.exists()) {
            FileWriter fw = new FileWriter(file);
            fw.write("");
            fw.flush();
        } else {
            file.createNewFile();
        }
        PrintStream out = System.out;
        System.setOut(new PrintStream(new FileOutputStream(file)));
        long start = System.currentTimeMillis();
        fileProcess.start();
        long end = System.currentTimeMillis();
        System.setOut(out);
        System.out.println("文件处理完成，耗费时间：" + String.format("%.2f", (end - start) / 1000.0) + "s，详细日志地址：" + file.getAbsolutePath());
    }
}

